/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Desktop_AddAddress.java
 *
 * Created on Mar 31, 2011, 2:11:52 PM
 */
package DesktopGUIpackage;

import Controller.DesktopController;
import Controller.DesktopControllerHelper;
import DTO.Address;
import Utilities.ResponseMessages;

/**
 *
 * @author edaype
 */
public class Desktop_AddAddress extends javax.swing.JPanel {

    private DesktopController desktopController = null;
    private DesktopControllerHelper desktopControllerHelper = null;
    private Address addressVO = null;

    /** Creates new form Desktop_AddAddress */
    public Desktop_AddAddress(DesktopControllerHelper desktopControllerHelper) {
        this.desktopControllerHelper = desktopControllerHelper;
        desktopController = desktopControllerHelper.getDesktopController();
        addressVO = new Address();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ButtonPanel = new javax.swing.JPanel();
        RegisterButton = new javax.swing.JButton();
        ClearButton1 = new javax.swing.JButton();
        TitleLabel = new javax.swing.JLabel();
        ItemPanel = new javax.swing.JPanel();
        CityText = new javax.swing.JTextField();
        StreetText = new javax.swing.JTextField();
        CityLabel = new javax.swing.JLabel();
        AptText = new javax.swing.JTextField();
        ProvinceLabel = new javax.swing.JLabel();
        PostalText = new javax.swing.JTextField();
        StreetLabel = new javax.swing.JLabel();
        AptLabel = new javax.swing.JLabel();
        PostalLabel = new javax.swing.JLabel();
        ProvinceSelect = new javax.swing.JComboBox();
        StreetNoText = new javax.swing.JTextField();
        StreetNoLabel = new javax.swing.JLabel();
        StreetNoOut = new javax.swing.JLabel();
        PostalOut = new javax.swing.JLabel();
        CityOut = new javax.swing.JLabel();
        StreetOut = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        ButtonPanel.setBackground(new java.awt.Color(255, 255, 255));

        RegisterButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        RegisterButton.setText("Submit");
        RegisterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterButtonActionPerformed(evt);
            }
        });

        ClearButton1.setFont(new java.awt.Font("Tahoma", 0, 18));
        ClearButton1.setText("Clear Form");
        ClearButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ButtonPanelLayout = new javax.swing.GroupLayout(ButtonPanel);
        ButtonPanel.setLayout(ButtonPanelLayout);
        ButtonPanelLayout.setHorizontalGroup(
            ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ClearButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(RegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        ButtonPanelLayout.setVerticalGroup(
            ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ClearButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        TitleLabel.setFont(new java.awt.Font("Copperplate Gothic Bold", 2, 60));
        TitleLabel.setText("Add Address");

        ItemPanel.setBackground(new java.awt.Color(255, 255, 255));

        CityText.setFont(new java.awt.Font("Tahoma", 0, 24));

        StreetText.setFont(new java.awt.Font("Tahoma", 0, 24));

        CityLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        CityLabel.setText("City");

        AptText.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N

        ProvinceLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        ProvinceLabel.setText("Province");

        PostalText.setFont(new java.awt.Font("Tahoma", 0, 24));

        StreetLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        StreetLabel.setText("Street");

        AptLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        AptLabel.setText("Apt Number");

        PostalLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        PostalLabel.setText("Postal Code");

        ProvinceSelect.setFont(new java.awt.Font("Tahoma", 0, 24));
        ProvinceSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alberta", "British Columbia", "Manitoba", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Nunavut", "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon" }));
        ProvinceSelect.setSelectedIndex(1);

        StreetNoText.setFont(new java.awt.Font("Tahoma", 0, 24));

        StreetNoLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        StreetNoLabel.setText("Street Number");

        StreetNoOut.setFont(new java.awt.Font("Tahoma", 0, 24));

        PostalOut.setFont(new java.awt.Font("Tahoma", 0, 24));

        CityOut.setFont(new java.awt.Font("Tahoma", 0, 24));

        StreetOut.setFont(new java.awt.Font("Tahoma", 0, 24));

        javax.swing.GroupLayout ItemPanelLayout = new javax.swing.GroupLayout(ItemPanel);
        ItemPanel.setLayout(ItemPanelLayout);
        ItemPanelLayout.setHorizontalGroup(
            ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ItemPanelLayout.createSequentialGroup()
                .addGap(92, 92, 92)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(ItemPanelLayout.createSequentialGroup()
                            .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(CityLabel)
                                .addComponent(StreetLabel))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(StreetText, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                                .addComponent(StreetOut)))
                        .addGroup(ItemPanelLayout.createSequentialGroup()
                            .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(StreetNoLabel)
                                .addComponent(AptLabel))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(AptText, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                                .addComponent(StreetNoText, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(StreetNoOut, javax.swing.GroupLayout.Alignment.TRAILING))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ItemPanelLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(PostalLabel)
                            .addComponent(ProvinceLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ProvinceSelect, 0, 385, Short.MAX_VALUE)
                            .addComponent(PostalText, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                            .addComponent(CityOut, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                            .addComponent(CityText, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                            .addComponent(PostalOut, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE))))
                .addGap(137, 137, 137))
        );
        ItemPanelLayout.setVerticalGroup(
            ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ItemPanelLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AptText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AptLabel))
                .addGap(18, 18, 18)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StreetNoText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(StreetNoLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(StreetNoOut, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ItemPanelLayout.createSequentialGroup()
                        .addComponent(StreetText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(StreetOut, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CityText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(ItemPanelLayout.createSequentialGroup()
                        .addComponent(StreetLabel)
                        .addGap(24, 24, 24)
                        .addComponent(CityLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CityOut, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PostalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PostalLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PostalOut, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ProvinceSelect, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ProvinceLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ItemPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(TitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ItemPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 121, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TitleLabel))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void RegisterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegisterButtonActionPerformed
        // TODO add your handling code here:

        boolean isValid = false;
        isValid = validateFields();
        if (isValid) {
            addressVO.setStNo(Integer.parseInt(StreetNoText.getText()));
            addressVO.setPostCode(PostalText.getText());
            addressVO.setCity(CityText.getText());
            addressVO.setStreet(StreetText.getText());
            addressVO.setAptNo(AptText.getText());
            String province = ProvinceSelect.getSelectedItem().toString();
            Character pv = province.charAt(0);
            Character pv1 = province.charAt(province.indexOf(" ") + 1);
            String pvnce = String.valueOf(pv) + String.valueOf(pv1);
            addressVO.setProvince(pvnce);
            String response = desktopController.addAddress(addressVO);
            if (ResponseMessages.ADDRESS_UPDATE_SUCCESSFUL.equalsIgnoreCase(response)) {
                desktopController.setMessage(response);
                desktopControllerHelper.ManageAddressScreen();
            } else if (ResponseMessages.DATABASE_DOWN.equalsIgnoreCase(response)) {
                desktopControllerHelper.changeFrame(6);
            } else if (ResponseMessages.ADDRESS_NOT_UPDATE_SUCCESSFUL.equalsIgnoreCase(response)) {
                desktopControllerHelper.changeFrame(6);
            }
        }


    }//GEN-LAST:event_RegisterButtonActionPerformed

    private boolean validateFields() {

        boolean isValid = true;

        if ("".equalsIgnoreCase(StreetNoText.getText().trim())) {
            isValid = false;
            StreetNoOut.setText("Street Number Field Required");
        } else if ("".equalsIgnoreCase(StreetText.getText().trim())) {
            isValid = false;
            StreetOut.setText("Street is mandatory");
        } else if ("".equalsIgnoreCase(CityText.getText().trim())) {
            isValid = false;
            CityOut.setText("city is mandatory");
        } else if ("".equalsIgnoreCase(PostalText.getText().trim())) {
            isValid = false;
            PostalOut.setText("postal code is mandatory");
        } else {
            isValid = ValidatePostal();
            try {
                addressVO.setStNo(Integer.parseInt(StreetNoText.getText()));
            } catch (NumberFormatException nfe) {
                isValid = false;
                StreetNoOut.setText(
                        "Street Number should be numeric");
            }
        }

        return isValid;

    }
    private void ClearButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButton1ActionPerformed
        // TODO add your handling code here:
        AptText.setText("");
        CityText.setText("");
        CityOut.setText("");
        PostalText.setText("");
        StreetNoOut.setText("");
        StreetNoText.setText("");
        StreetText.setText("");
        StreetOut.setText("");
        PostalOut.setText("");
}//GEN-LAST:event_ClearButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AptLabel;
    private javax.swing.JTextField AptText;
    private javax.swing.JPanel ButtonPanel;
    private javax.swing.JLabel CityLabel;
    private javax.swing.JLabel CityOut;
    private javax.swing.JTextField CityText;
    private javax.swing.JButton ClearButton1;
    private javax.swing.JPanel ItemPanel;
    private javax.swing.JLabel PostalLabel;
    private javax.swing.JLabel PostalOut;
    private javax.swing.JTextField PostalText;
    private javax.swing.JLabel ProvinceLabel;
    private javax.swing.JComboBox ProvinceSelect;
    private javax.swing.JButton RegisterButton;
    private javax.swing.JLabel StreetLabel;
    private javax.swing.JLabel StreetNoLabel;
    private javax.swing.JLabel StreetNoOut;
    private javax.swing.JTextField StreetNoText;
    private javax.swing.JLabel StreetOut;
    private javax.swing.JTextField StreetText;
    private javax.swing.JLabel TitleLabel;
    // End of variables declaration//GEN-END:variables

    private boolean ValidatePostal() {

        boolean isValid = true;
        if (PostalText.getText().length() != 6) {
            isValid = false;
            PostalOut.setText("Less than 6");
        }

        String option = (String) ProvinceSelect.getSelectedItem();

        char[] postal = PostalText.getText().toUpperCase().toCharArray();

        int ascii1 = PostalText.getText().charAt(1);
        int ascii2 = PostalText.getText().toUpperCase().charAt(2);
        int ascii3 = PostalText.getText().charAt(3);
        int ascii4 = PostalText.getText().toUpperCase().charAt(4);
        int ascii5 = PostalText.getText().charAt(5);

        if (ascii1 < 48 || ascii1 > 57) { //Is Number
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        } else if (ascii2 < 65 || ascii2 > 90) {
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        } else if (ascii3 < 48 || ascii3 > 57) {
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        } else if (ascii5 < 48 || ascii5 > 57) {
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        } else if (ascii4 < 65 || ascii4 > 90) {
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        } else {
            PostalOut.setText("");
        }

        if (postal[0] == 'A' || postal[0] == 'B' || postal[0] == 'C' || postal[0] == 'E' || postal[0] == 'G' || postal[0] == 'H'
                || postal[0] == 'J' || postal[0] == 'K' || postal[0] == 'L' || postal[0] == 'M' || postal[0] == 'N' || postal[0] == 'P'
                || postal[0] == 'R' || postal[0] == 'S' || postal[0] == 'T' || postal[0] == 'V' || postal[0] == 'X' || postal[0] == 'Y') {
            if (postal[0] == 'A' && option.equals("Newfoundland and Labrador") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'B' && option.equals("Nova Scotia") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'C' && option.equals("Prince Edward Island") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'E' && option.equals("New Brunswick") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'G' && option.equals("Quebec") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'H' && option.equals("Quebec") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'J' && option.equals("Quebec") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'K' && option.equals("Ontario") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'L' && option.equals("Ontario") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'M' && option.equals("Ontario") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'N' && option.equals("Ontario") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'P' && option.equals("Ontario") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'R' && option.equals("Manitoba") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'S' && option.equals("Saskatchewan") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'T' && option.equals("Alberta") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'V' && option.equals("British Columbia") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'X' && option.equals("Northwest Territories") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'X' && option.equals("Nunavut") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            } else if (postal[0] == 'Y' && option.equals("Yukon") == false) {
                isValid = false;
                PostalOut.setText("Postal Code Invalid");
            }
        } else {
            isValid = false;
            PostalOut.setText("Postal Code Invalid");
        }

        return isValid;
    }
}
